package com.owulia.leetcode.num.stack;

public class Stack {

    public static boolean isValid(String s) {
        if (s.length() < 2 || s.length() % 2 == 1) {
            return false;
        }
        char chars[] = new char[s.length()];
        int index = 0;
        for (int i = 0; i < s.length(); i++) {
            char charCur = s.charAt(i);
            if ('{' == charCur || '(' == charCur || '[' == charCur) {
                chars[index] = charCur;
                index++;
            } else if ('}' == charCur || ')' == charCur || ']' == charCur) {
                if (index >= 0 &&
                        (('}' == charCur && chars[index - 1] == '{') || (')' == charCur && chars[index - 1] == '(') || (']' == charCur && chars[index - 1] == '['))) {
                    index--;
                } else {
                    return false;
                }
            }
        }
        return index == 0;
    }

    public static void main(String[] args) {
        MinStack minStack = new MinStack();
        minStack.push(-2);
        minStack.push(-0);
        minStack.push(-3);
        minStack.getMin();
    }
}
